package models

import (
	"rongyy/src/app"
	"rongyy/src/middlewares"
)

type MedicalGuideRecordModel struct {
	BaseModel    `xorm:"extends"`
	TemplateType string `json:"template_type"`
	PatId        string `json:"pat_id"`
	VisitCardNo  string `json:"visit_card_no"`
	First        string `json:"first"`
	Url          string `json:"url"`
	Keywords     struct {
		Keyword1 string `json:"keyword1"`
		Keyword2 string `json:"keyword2"`
	}
	Remark string `json:"remark"`
}

func (mgrm *MedicalGuideRecordModel) TableName() string {
	return "medical_guide_record"
}

func (mgrm *MedicalGuideRecordModel) Insert() error {
	_, err := app.DB().Insert(mgrm)
	if err != nil {
		middlewares.Logger.Println("ERROR - medical_guide_record Insert failed ", err)
		//return errors.New("保存失败")
	}
	return nil
}

func (mgrm *MedicalGuideRecordModel) QueryByPatientId(pid string) error {
	mgrms := make([]MedicalGuideRecordModel, 0)
	_, err := app.DB().Where("pat_id = ?", pid).FindAndCount(&mgrms)
	if err != nil {
		middlewares.Logger.Println("ERROR - medical_guide_record Insert failed ", err)
		//return errors.New("保存失败")
	}
	return nil
}
